<template>
  <div class="my-login">
    <div class="form">
      <el-card>
        <div class="title">登录</div>
        <el-form v-loading="loading">
          <el-form-item label>
            <el-input v-model="form.account" placeholder="请输入账号"></el-input>
          </el-form-item>
          <el-form-item label>
            <el-input v-model="form.pwd" placeholder="请输入密码" type="password" show-password></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="success" @click="onSubmit()">登录</el-button>
          </el-form-item>
          <router-link tag="a" target="_blank" :to="{name:'pwd'}" class="find-pwd">忘记密码？</router-link>
        </el-form>
      </el-card>
    </div>
  </div>
</template>

<script>
import util from '../../util.js'
export default {
  name: "name",
  data: function() {
    return {

      form:{
        account:'',
        pwd:''
      },
      loading:false,
    };
  },
  mounted:function(){
  },
  methods: {
    onSubmit(){
      this.loading=true
      //util.sleep(10000)
       this.axios.post("user/login",this.form)
      .then(res=>{
        this.loading=false
        if(res.data.userData==null){
         // console.log(this)
          this.$message.error("账号或者密码错误!")
          return;
        }
        localStorage.setItem("userData",JSON.stringify(res.data.userData))
        this.$store.commit("setUser",res.data.userData)
        this.$router.push({name:'index'})
      }) 

    }
  }
};
</script>

<style lang="scss" scoped>
.my-login {
  height: 600px;
  margin-top: 50px;
  .form {
    width: 50%;
    margin: 0 auto;
    height: 300px;
    .title {
      text-align: center;
      font-size: 30px;
      line-height: 60px;
      font-weight: bold;
      color: #909399;
    }
    .el-button {
      width: 100%;
    }
    .find-pwd {
      margin-left: 2px;
      color: #c0c4cc;
    }
  }
}
</style>    